<?php 
	
?>
<?php
	include("include1.php");
	//ini_set('default_charset','utf-8');
	//header("Content-type: application/json; charset=utf-8");
	
	$verb = $_SERVER["REQUEST_METHOD"];
	//echo $verb;
	if($verb == "GET")
	{
		if(isset($_REQUEST["xoa"]))
		{
			echo $_REQUEST["xoa"];
			$sql = "delete from danhsachcongtrinh where id='" . $_REQUEST["xoa"] . "'";echo $sql;
			$rs = mysql_query($sql);
			
		}
		else
		{
			header("Content-type: application/json; charset=utf-8");
			$arr = array();
			
			$rs = mysql_query("select `id` as `CTid`, `TenCT`, `Khac` from `danhsachcongtrinh`");
			$temp="";
			while($obj = mysql_fetch_object($rs))
			{
					$arr[] = $obj;					
			}
			echo "{\"data\":" . json_encode($arr , JSON_UNESCAPED_UNICODE) . "}";
		}
	}
	
	if($verb == "POST")
	{
		$CTid = mysql_real_escape_string($_POST["CTid"]);
		$TenCT = mysql_real_escape_string($_POST["TenCT"]);
		$Khac = mysql_real_escape_string($_POST["Khac"]);
		
		$sql = sprintf("update danhsachcongtrinh set TenCT = '%s', Khac = '%s' where id = '%s'", $TenCT, $Khac, $CTid);
		$rs = mysql_query($sql);
		
		if ($rs) {
        echo json_encode($rs);
		}
		else {
			header("HTTP/1.1 500 Internal Server Error");
			echo "Không thể cập nhật công trình: " .$TenCT;
		}
	}
	
	
?>